/*
 * @Descripttion: 
 * @Author: cuidm
 * @Date: 2022-03-31 14:58:28
 * @LastEditors: cuidm
 * @LastEditTime: 2022-09-28 14:57:30
 */
import React, { useState, useEffect, Fragment } from "react";
import { message } from "antd";;
import { HcpTipModal } from "@/components";
import cmdbres from "@/data/cmdbres";
import request from "@/utils/request";

const DeleteInstanceModal = ({id, info, visible, setVisible, onDeleteFinish}) => {
    const [loading, setLoading] = useState(false);
    const onFinish = async () => {
        setLoading(true);
        let res = await request({
            ...cmdbres.deleteResource,
            data: {
                cm_module_id: id,
                cm_unids: info
            }
        });
        setLoading(false);
        setVisible(false);
        if (res && (res.code == 200)) {
            message.success("删除成功！");
            if (typeof onDeleteFinish == "function") onDeleteFinish(res);
        } else {
            if(res) message.error(res.msg);
        }
    };
    
    return (
        <HcpTipModal
            title="删除"
            visible={visible}
            loading={loading}
            onFinish={onFinish}
            onCancel={() => { setVisible(false) }}
            content={
                <>
                    <div className="main-content">
                        <span className="main-content-info">{info?.length > 1 ? "确定要批量删除吗？" : "确定要删除吗？"}</span>
                    </div>
                    <div className="gray" style={{marginLeft: 5}}>删除资源同时会删除关联关系</div>
                </>
            }
      />
    )
};

export default DeleteInstanceModal;
